package com.gitee.funcy.disruptorlearn.ch03.multi;

import com.lmax.disruptor.WorkHandler;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class Consumer implements WorkHandler<Order> {

    private String consumerId;

    private static AtomicInteger count = new AtomicInteger(0);

    public Consumer(String consumerId) {
        this.consumerId = consumerId;
    }

    @Override
    public void onEvent(Order order) throws Exception {
        Random random = new Random();
        Thread.sleep(1 * random.nextInt(5));
        System.out.println("当前消费者" + this.consumerId + ", 消费id:" + order.getId());
        count.incrementAndGet();
    }

    public static int getCount() {
        return count.get();
    }
}
